<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>班级管理 - 智能教育系统</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            margin: 0;
            padding-top: 80px;
        }

        .manage-container {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 2rem;
            animation: fadeIn 0.5s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .class-card {
            background: white;
            border-radius: 15px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            margin-bottom: 1.5rem;
        }

        .class-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
        }

        .btn-primary {
            background: linear-gradient(135deg, #6e8efb, #a777e3);
            color: white;
            padding: 0.75rem 1.5rem;
            border-radius: 25px;
            transition: all 0.3s ease;
            border: none;
            font-weight: 600;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(110, 142, 251, 0.3);
        }

        .form-control {
            width: 100%;
            padding: 0.75rem 1rem;
            border: 2px solid #e2e8f0;
            border-radius: 8px;
            transition: all 0.3s ease;
            background: #f8fafc;
        }

        .form-control:focus {
            outline: none;
            border-color: #6e8efb;
            box-shadow: 0 0 0 3px rgba(110, 142, 251, 0.1);
        }

        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
        }

        .modal.active {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .modal-content {
            background: white;
            padding: 2rem;
            border-radius: 15px;
            width: 90%;
            max-width: 600px;
            animation: modalFadeIn 0.3s ease;
        }

        @keyframes modalFadeIn {
            from {
                opacity: 0;
                transform: scale(0.9);
            }
            to {
                opacity: 1;
                transform: scale(1);
            }
        }

        .student-list {
            max-height: 300px;
            overflow-y: auto;
        }

        .student-item {
            display: flex;
            align-items: center;
            padding: 0.75rem;
            border-bottom: 1px solid #e2e8f0;
        }

        .student-item:last-child {
            border-bottom: none;
        }

        .student-item:hover {
            background: #f8fafc;
        }
    </style>
</head>
<body>
    <!-- 引入导航栏 -->
    <div th:replace="~{fragments/navbar :: navbar}"></div>

    <div class="manage-container">
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-3xl font-bold text-gray-800">班级管理</h1>
            <button class="btn-primary" onclick="showCreateClassModal()">创建班级</button>
        </div>

        <!-- 提示消息 -->
        <div th:if="${success}" class="alert bg-green-100 text-green-700 p-4 rounded-lg mb-4" th:text="${success}"></div>
        <div th:if="${error}" class="alert bg-red-100 text-red-700 p-4 rounded-lg mb-4" th:text="${error}"></div>

        <!-- 班级列表 -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            <div th:each="class : ${classes}" class="class-card p-6">
                <h3 class="text-xl font-semibold mb-2" th:text="${class.className}"></h3>
                <p class="text-gray-600 mb-2" th:text="${'年级：' + class.grade}"></p>
                <p class="text-gray-600 mb-4" th:text="${'学生人数：' + class.studentCount}"></p>
                <div class="flex justify-between items-center">
                    <button class="btn-primary text-sm" th:onclick="'showAddStudentModal(' + ${class.id} + ')'">添加学生</button>
                    <button class="btn-primary text-sm bg-red-500" th:onclick="'deleteClass(' + ${class.id} + ')'">删除班级</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 创建班级模态框 -->
    <div class="modal" id="createClassModal">
        <div class="modal-content">
            <h2 class="text-2xl font-bold mb-4">创建班级</h2>
            <form th:action="@{/class/create}" method="post" id="createClassForm">
                <div class="mb-4">
                    <label class="block text-gray-700 mb-2">班级名称</label>
                    <input type="text" name="className" class="form-control" required>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700 mb-2">年级</label>
                    <select name="grade" class="form-control" required>
                        <option value="">选择年级</option>
                        <option value="1">一年级</option>
                        <option value="2">二年级</option>
                        <option value="3">三年级</option>
                        <option value="4">四年级</option>
                        <option value="5">五年级</option>
                        <option value="6">六年级</option>
                    </select>
                </div>
                <div class="flex justify-end space-x-4">
                    <button type="button" class="btn-primary bg-gray-500" onclick="hideCreateClassModal()">取消</button>
                    <button type="submit" class="btn-primary">创建</button>
                </div>
            </form>
        </div>
    </div>

    <!-- 添加学生模态框 -->
    <div class="modal" id="addStudentModal">
        <div class="modal-content">
            <h2 class="text-2xl font-bold mb-4">添加学生</h2>
            <form th:action="@{/class/add-student}" method="post" id="addStudentForm">
                <input type="hidden" name="classId" id="classId">
                <div class="mb-4">
                    <label class="block text-gray-700 mb-2">学生姓名</label>
                    <input type="text" name="studentName" class="form-control" required>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700 mb-2">学号</label>
                    <input type="text" name="studentId" class="form-control" required>
                </div>
                <div class="flex justify-end space-x-4">
                    <button type="button" class="btn-primary bg-gray-500" onclick="hideAddStudentModal()">取消</button>
                    <button type="submit" class="btn-primary">添加</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        function showCreateClassModal() {
            document.getElementById('createClassModal').classList.add('active');
        }

        function hideCreateClassModal() {
            document.getElementById('createClassModal').classList.remove('active');
        }

        function showAddStudentModal(classId) {
            document.getElementById('classId').value = classId;
            document.getElementById('addStudentModal').classList.add('active');
        }

        function hideAddStudentModal() {
            document.getElementById('addStudentModal').classList.remove('active');
        }

        function deleteClass(classId) {
            if (confirm('确定要删除这个班级吗？')) {
                // TODO: 实现删除班级功能
                alert('删除班级功能开发中...');
            }
        }

        // 点击模态框外部关闭
        document.querySelectorAll('.modal').forEach(modal => {
            modal.addEventListener('click', function(e) {
                if (e.target === this) {
                    this.classList.remove('active');
                }
            });
        });
    </script>
</body>
</html> 